
package com.ifcar.app.model;

import com.ifcar.app.rss.GetComments;
import com.ifcar.app.util.HttpUtils;
import com.ifcar.app.util.ModelUtils;
import com.ifcar.app.util.NeteaseHttpClient;
import com.ifcar.app.activity.R;

import org.json.JSONObject;

import android.content.Context;
import android.text.TextUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReplyMe {

    public static final String URL_REPLYME = "http://comment.api.163.com/api/json/post/list/new/reply2me/%s/%d/%d/%d/%d/%d";//"http://comment.163.com/reply/api/reply2me.jsp?userId=%s&page=%d&pageSize=%d";

    // 以下返回异常参数名
    public static final String FAILED = "0";// PARAM_SUCCESS中异常

    public static final String PARAM_SUCCESS = "success";// 0,表示接口异常

    public static final String PARAM_ERROR = "error";// 表明异常原因

    // 以下返回字段参数名
    public static final String PARAM_LIST = "sList"; // 为json数组,包含当前分页的所有帖子信息,sList中的每一条json对象代表一条跟帖

    public static final String PARAM_PAGE = "page";// 当前请求页码

    public static final String PARAM_USERID = "userId";// 所要查询的用户id

    public static final String PARAM_PAGE_SIZE = "pageSize";// 请求页列表大小

    public static final String PARAM_TOTAL_NOTICE_COUNT = "totalnoticecount";// 所查询用户的评论提醒总数

    public static final String PARAM_NEW_NOTICE_COUNT = "newnoticecount";// 所查询用户的未读评论提醒数量

    // 以下list单字段
    public static final String PARAM_LN = "ln"; // 是否是未读信息. true:未读；false:已读
    
    public static final String PARAM_IB = "ib"; // 是否盖楼。0否；1是

    public static final String PARAM_AP = "ap";// 发表时间(毫秒数)

    public static final String PARAM_AC = "ac";// 均为” reply2me”,代表评论提醒,其他程序可忽略
    
    public static final String PARAM_LV = "lv";// 跟帖的楼层数

    public static final String PARAM_FU = "fu";// 发帖用户id

    public static final String PARAM_FN = "fn";// 发帖用户昵称

    public static final String PARAM_FQ = "fq";// 跟帖界面显示的用户信息，其他程序可忽略

    public static final String PARAM_SI = "si";// 原始来源用户，其他程序可忽略

    public static final String PARAM_BD = "bd";// 跟帖内容
    
    public static final String PARAM_BI = "bi";// 所在版面
    public static final String PARAM_PI = "pi";// 所在版面


    public static Map<String, Object> getReplyMe(Context context, String userId,
            int page, int pageSize) {
        Map<String, Object> result = null;

        String url = String.format(URL_REPLYME, userId, page, pageSize, 10, 2, 2);
        String str = HttpUtils.getResponseFromGetUrl(url, 30000, context);

        if (!TextUtils.isEmpty(str)) {
            try {
                JSONObject json = new JSONObject(str);
                result = ModelUtils.json2Map(json);
            } catch (Exception e) {
                result = new HashMap<String, Object>();
                result.put(PARAM_SUCCESS, FAILED);
                result.put(PARAM_ERROR, context.getText(R.string.msg_ret_error));
                NeteaseHttpClient.removeCache(context, url);
            }
        }

        if (result == null) {
            result = new HashMap<String, Object>();
            result.put(PARAM_SUCCESS, FAILED);
            result.put(PARAM_ERROR, context.getText(R.string.msg_net_error));
        }

//        System.out.println(result);
        return result;
    }
}
